#include <graphics/GLRenderBufferObject.h>

namespace ne
{
    GLRenderBufferObject::GLRenderBufferObject()
        : GLObject(),
          mFormat(TF_DEPTH_COMPONENT),
          mWidth(0),
          mHeight(0)
    {
        glGenRenderbuffers(1, &mSource);
    }

    void GLRenderBufferObject::setStorage(const TextureFormat format, const uint32_t width, const uint32_t height)
    {
        mFormat = format;
        mWidth = width;
        mHeight = height;
        glBindRenderbuffer(GL_RENDERBUFFER, mSource);
        glRenderbufferStorage(GL_RENDERBUFFER, mFormat, mWidth, mHeight);
    }

    TextureFormat GLRenderBufferObject::getFormat() const
    {
        return mFormat;
    }

    uint32_t GLRenderBufferObject::getWidth() const
    {
        return mWidth;
    }

    uint32_t GLRenderBufferObject::getHeight() const
    {
        return mHeight;
    }

    void GLRenderBufferObject::bind()
    {
        glBindRenderbuffer(GL_RENDERBUFFER, mSource);
    }

    bool GLRenderBufferObject::isRenderBuffer()
    {
        if (glIsRenderbuffer(mSource) == GL_TRUE)
        {
            return true;
        }
        return false;
    }

    GLRenderBufferObject::~GLRenderBufferObject()
    {
        glDeleteRenderbuffers(1, &mSource);
    }
}
